var EventEmitter = require('events').EventEmitter;

var event = new EventEmitter();

event.on('hi', function() {
	console.log('event hi');
});

setTimeout(function() {
	event.emit('hi');

}, 1000);

event.on('hello', function(arg1, arg2) {
	console.log('hello with arg', arg1, arg2);
});

// just listen once, then remove automatic
event.once('hello', function(arg1,arg2) {
	console.log('hello conce with', arg1, arg2);
});

var listen = function(arg1, arg2) {
	console.log('hello listener', arg1,arg2);
}

event.addListener('hello', listen);

console.log('hello listener count:', event.listenerCount('hello'));

event.emit('hello', 'arg1','arg2');

event.removeListener('hello', listen);

console.log('hello listener count:', event.listenerCount('hello'));

// throw e, error event is default error event, emit error = throw e
event.emit('error');
